using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _controls_DateTimeControl : System.Web.UI.UserControl
{
    private bool _itemsLoaded;
    private int _startYear = DateTime.Now.Year;
    private int _endYear = DateTime.Now.AddYears(20).Year;
    private int _selectedYear;

    public int StartYear
    {
        get
        {
            return this._startYear;
        }

        set
        {
            this._startYear = value;
        }
    }

    public int EndYear
    {
        get
        {
            return this._endYear;
        }

        set
        {
            this._endYear = value;
        }
    }

    public int Month
    {
        get
        {
            return int.Parse(this.drpMonths.SelectedValue);
        }
    }

    public int SelectedYear
    {
        get
        {
            return int.Parse(this.drpYear.SelectedValue);
        }

        set
        {
            this._selectedYear = value;

            if(this.drpYear.Items.FindByValue(value.ToString()) != null)
                this.drpYear.SelectedValue = _selectedYear.ToString();
        }
    }

    public int SelectedMonth
    {
        get
        {
            return int.Parse(this.drpMonths.SelectedValue);
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            FillYearsDropDown();
        }
    }

    private void FillYearsDropDown()
    {
        this.drpYear.Items.Clear();

        for (int i = this._startYear; i <= this._endYear; i++)
        {
            this.drpYear.Items.Add(new ListItem(i.ToString()));
        }

        if(this._selectedYear != 0)
            this.drpYear.SelectedValue = this._selectedYear.ToString();

        _itemsLoaded = true;
    }

}
